package red.service.impl;

import red.dao.ArticleDao;
import red.dao.impl.ArticleDaoImpl;
import red.model.ArticleModel;
import red.service.ArticleService;
import red.util.Model;

import java.util.List;
import java.util.UUID;

public class ArticleServiceImpl implements ArticleService {

    private ArticleDao articleDao = new ArticleDaoImpl();

    @Override
    public ArticleModel deletearticle(Model model) {
        String headline = (String) model.get("article");
        ArticleModel articleModel = new ArticleModel();
        articleModel.setHeadline(headline);
        articleModel.setColumn_id(UUID.randomUUID().toString());
        return articleDao.deleteArticle(articleModel);
    }

    @Override
    public List<ArticleModel> selectarticle(Model model) {

        ArticleModel articleModel = new ArticleModel();
        String article = (String) model.get("article");

        if (article.equals("headline")){
            String headline = model.getString("headline");
            articleModel.setHeadline(headline);
            return articleDao.selectArticle(articleModel);
        }
        if (article.equals("column_name")){
            String column_name = model.getString("column_name");
            articleModel.setColumn_name(column_name);
            return articleDao.selectArticleColumn(articleModel);
        }
        if (article.equals("user_name")) {
            String user_name = model.getString("user_name");
            articleModel.setUser_name(user_name);
            return articleDao.selectArticleUser(articleModel);
        }
        return null;
    }

    @Override
    public List<ArticleModel> selectq(Model model) {
        ArticleModel articleModel = new ArticleModel();
        articleModel.setColumn_id(UUID.randomUUID().toString());
        return articleDao.selectq(articleModel);
    }


}
